/**
 *
 * @author cookie
 * 
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */

/**
 * @param {TreeNode} t1
 * @param {TreeNode} t2
 * @return {TreeNode}
 */

var mergeTrees = function(t1, t2) {
    // 两树都没有
    if (!t1 && !t2) return null

    // 一颗树没有
    if(!t1) return t2
    if(!t2) return t1

    // 两棵树都存在

    t1.val = t1.val + t2.val
    t1.left = mergeTrees(t1.left, t2.left)
    t1.right = mergeTrees(t1.right, t2.right)
    return t1
};

const t1 = {
    val :100,
    left: {
        val: 120,
        left: {
            val:120,
            left:300
        }
    },
    right: {
        val:200,
        left: {
            val:500,
            right:100
        },
        right: {
            val:35,
            left:{
                val:23,
                right:100
            }
        }

    }
}


const t2 = {
    val :111,
    left: {
        val: 120,
        right: {
            val:120,
            left:300
        }
    },
    right: {
        val:200,
        left: {
            val:500,
            right:100
        },
        right: {
            val:35,
            left:{
                val:23,
                right:100
            }
        }

    }
}
const result = mergeTrees(t1, t2)
console.log(result);
